<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <script type="text/javascript" src="./lib/vue-2.4.0.js"></script>
</head>
<body>

    <div id="app">
        <com1 :parentmsg="msg" @func="getMsgFromSon"></com1>
    </div>

    <template id="tmpl">
        <div>
            <h1>这是子组件---{{ parentmsg }} </h1>
            <input type="button" @click="sendMsg" value="向父组件传递信息" />
        </div>
    </template>
    <script type="text/javascript">
        var com1 = {
            template: '#tmpl',
            data(){
                return {
                    msg: '做一个孝顺的孩子'
                }
            },
            methods: {
                sendMsg(){
                    this.$emit('func', this.msg);
                }
            },
            props: ['parentmsg']
        }

        // 创建 Vue实例，得到 ViewModel
        var vm = new Vue({
            el: '#app',
            data: {
                msg: '叫爸爸吧',
                msgFromSon: ''
            },
            methods: {
                getMsgFromSon(data){
                    this.msgFromSon = data;
                    console.log(this.msgFromSon);
                }
            },
            components: {
                com1
            }
        });
    </script>
</body>
</html>